package com.tanhua.server.controller;

import com.tanhua.server.service.PeachblossomService;
import com.tanhua.server.vo.PeachblossomVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("peachblossom23")
public class PeachblossomController {
    @Autowired
    private PeachblossomService peachblossomService;
    //保存桃花传音
    @PostMapping
    public ResponseEntity<Boolean> savePeachblossom(@RequestParam(value = "soundFile23") MultipartFile soundFile){
        try {
            //传入桃花传音
            String s = peachblossomService.savePeachblossom(soundFile);
            //返回桃花传音ID
            if(StringUtils.isNotEmpty(s)){
                return ResponseEntity.ok(true);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    //获取桃花传音
    @GetMapping
    public ResponseEntity<PeachblossomVo> getPeachblossom(){
        try {
            PeachblossomVo peachblossomVo = peachblossomService.getPeachblossom();
            if (null!=peachblossomVo){
                return ResponseEntity.ok(peachblossomVo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
